import { getPayType,getOrderStatus } from '@/API/api.js'
let setIntervalOrderStatus;
export default function() {
	// 支付类型
	const handlePayType = (params,callback) => {
		getPayType(params).then(res => {
			const {code,data}=res
			callback(code===2000 ? data : {country:'',payTypes:[]})
		}).catch(()=>{});
	}
	// 订单状态查询[接口]
	    const handleOrderStatus = (orderId,callback) => {
	        getOrderStatus({ orderId }).then((res) => {
				const {code,data} = res;
				if(code===2000){
					const { status,classifyId } = data;
					console.log('status--', status);
					if (status!='pay'&&status!='create'){
					    handleClear();
						callback(status,classifyId);
					}
				}
	        }).catch(()=>{});
	    };
	    // 订单状态查询(定时器)
	    const orderStatusTime = (orderId,callback) => {
	        setIntervalOrderStatus = setInterval(function () {
	            handleOrderStatus(orderId,callback);
	        }, 2000);
	    };
	    const handleClear = ()=>{
			clearInterval(setIntervalOrderStatus);
	    }
		// onUnload(){
		// 	handleClear()
		// }
	return {
		handlePayType,
		orderStatusTime,
		handleClear
	}
}
